home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CICA 1995 August
/
CICA - The Ultimate Collection of Shareware for Windows (Disc 2) (August 1995).iso
/
disc2
/
programr
/
stdg44.exe
/
lha
/
PROGRESS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-10
|
2KB
|
86 lines
/*
* Draw a progress bar when the user presses a mouse button.
*/
#include <stdio.h>
#include "stdg.h"
/* Number of steps to perform in progress bar drawing */
#define NSTEPS 23
/* Total time in seconds to complete progress bar */
#define TOTALTIME 10
/* Time in millisecs for each step */
#define STEPTIME (TOTALTIME*1000/NSTEPS)
rectangle rcenter(rectangle r1, rectangle r2) /* center r1 on r2 */
{
long w1, h1, w2, h2;
w1 = dx(r1);
h1 = dy(r1);
w2 = dx(r2);
h2 = dy(r2);
return rdiag(r2.min.x + (w2-w1)/2, r2.min.y + (h2-h1)/2, w1, h1);
}
void draw_progress(bitmap *b)
{
int i;
point p;
char buf[100];
rectangle r, r2;
r = rect(0,0,200,sys_font->height+6);
r = rcenter(r, b->r);
start_timer(STEPTIME);
for (i=0; i<=NSTEPS; i++)
{
/* clear and draw the rectangle */
draw_rect(b, r, -1, BLACK);
fill_rect(b, r, WHITE);
/* print a completion percentage into a string */
sprintf(buf, "%d%% Complete", i*100/NSTEPS);
/* find the string size */
p = strsize(sys_font, buf);
/* center the string */
p = addp(divp(subp(subp(r.max, r.min), p), 2), r.min);
/* draw it at the calculated point */
draw_string(b, p, sys_font, buf, BLACK);
/* draw the progress bar */
r2 = r;
r2.max.x = r.min.x + (dx(r)*i/NSTEPS);
fill_rect(b, r2, BLUE | notDorS);
/* wait for next timer event */
get_timer();
}
/* stop the timer */
start_timer(0);
}
int main(int argc, char **argv)
{
window *w;
mouse m;
ginit("Progress Bar Demo", NULL, NULL);
w = new_window("Progress!", rdiag(50,50,250,60), Titlebar | Maximize);
show_window(w);
while (1) {
m = get_mouse(w);
if (m.kind & MouseUp)
draw_progress(w->b);
}
return 0;
}